package org.testmyapp.entities;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.testmyapp.persistence.BusinessObjectMarker;

@Entity
@IdClass(TariffInstancePk.class)
public class TariffInstance implements BusinessObjectMarker {

	/**
	 * 
	 */
	private static final long serialVersionUID = 934859657742135642L;

	public static String tableName = "TariffInstance";

	@Id
	@ManyToOne
	@JoinTable(name = "ip_fk", joinColumns = {
			@JoinColumn(name = "ip_contract_fk", referencedColumnName = "contract_id_fk"),
			@JoinColumn(name = "ip_person_fk", referencedColumnName = "person_id_fk") })
	private InsuredPerson ip;
	@Id
	@ManyToOne
	@JoinColumn(name = "tarif_fk")
	private TarifDefinition tarif;
	@Temporal(value = TemporalType.DATE)
	private Date tariffBegin;
	@Column(nullable = true)
	@Temporal(value = TemporalType.DATE)
	private Date tariffEnd;

	public InsuredPerson getIp() {
		return ip;
	}

	public void setIp(InsuredPerson ip) {
		this.ip = ip;
	}

	public TarifDefinition getTarif() {
		return tarif;
	}

	public void setTarif(TarifDefinition tarif) {
		this.tarif = tarif;
	}

	public Date getTariffBegin() {
		return tariffBegin;
	}

	public void setTariffBegin(Date tariffBegin) {
		this.tariffBegin = tariffBegin;
	}

	public Date getTariffEnd() {
		return tariffEnd;
	}

	public void setTariffEnd(Date tariffEnd) {
		this.tariffEnd = tariffEnd;
	}

	public String toString() {
		String result = "";
		result += "Tariff " + tarif.getIdentifier() + " for contract/ip"
				+ ip.getContract() + "/" + ip.getPerson().getFirstName() + " "
				+ ip.getPerson().getLastName();
		return result;
	}

}
